package com.tanhua.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.server.mapper.SettingsMapper;
import com.tanhua.server.pojo.Settings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 西楚霸王
 * @date 2020/12/1 23:09
 */
@Service
public class SettingsService {

    @Autowired
    private SettingsMapper settingsMapper;

    public Settings querySettingsByUserId(Long userId) {
        QueryWrapper<Settings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return this.settingsMapper.selectOne(queryWrapper);
    }

    public void updateNotification(Long id, Boolean likeNotification, Boolean pinglunNotification, Boolean gonggaoNotification) {
    Settings settings = new Settings();
    settings.setLikeNotification(likeNotification);
    settings.setGonggaoNotification(gonggaoNotification);
    settings.setPinglunNotification(pinglunNotification);

        QueryWrapper<Settings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",id);

        this.settingsMapper.update(settings,queryWrapper);
    }
}
